import Vue from 'vue';
import Router from 'vue-router';
import routes from './route'
import Cookie from 'js-cookie'
Vue.use(Router);

const router = new Router({
    base:'admin',
    mode:'history',
    routes:routes
});

router.beforeEach((to,from,next)=>{
   const role = Cookie.get('access_token');
   if(!role && to.path !='/login'){
       next('/login');
   }else if(to.meta.permission){
       //若果好似管理面权限则可进入
       role==='admin'? next():next('/403');
   }else{
       // 简单的判断IE10及以下不进入富文本编辑器，该组件不兼容
       if(navigator.userAgent.indexOf('MSIE') > -1 && to.path === '/editor'){
           Vue.prototype.$alert('vue-quill-editor组件不兼容IE10及以下浏览器，请使用更高版本的浏览器查看', '浏览器不兼容通知', {
               confirmButtonText: '确定'
           });
       }else{
           next();
       }
   }

});
export default router;